package com.ruoyi.members.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.members.domain.MhUser;
import com.ruoyi.members.service.IMhUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会员信息Controller
 * 
 * @author yuekai
 * @date 2025-11-14
 */
@RestController
@RequestMapping("/members/members")
public class MhUserController extends BaseController
{
    @Autowired
    private IMhUserService mhUserService;

    /**
     * 查询会员信息列表
     */
    @PreAuthorize("@ss.hasPermi('members:members:list')")
    @GetMapping("/list")
    public TableDataInfo list(MhUser mhUser)
    {
        startPage();
        List<MhUser> list = mhUserService.selectMhUserList(mhUser);
        return getDataTable(list);
    }

    /**
     * 导出会员信息列表
     */
    @PreAuthorize("@ss.hasPermi('members:members:export')")
    @Log(title = "会员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MhUser mhUser)
    {
        List<MhUser> list = mhUserService.selectMhUserList(mhUser);
        ExcelUtil<MhUser> util = new ExcelUtil<MhUser>(MhUser.class);
        util.exportExcel(response, list, "会员信息数据");
    }

    /**
     * 获取会员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('members:members:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mhUserService.selectMhUserById(id));
    }

    /**
     * 新增会员信息
     */
    @PreAuthorize("@ss.hasPermi('members:members:add')")
    @Log(title = "会员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MhUser mhUser)
    {
        return toAjax(mhUserService.insertMhUser(mhUser));
    }

    /**
     * 修改会员信息
     */
    @PreAuthorize("@ss.hasPermi('members:members:edit')")
    @Log(title = "会员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MhUser mhUser)
    {
        return toAjax(mhUserService.updateMhUser(mhUser));
    }

    /**
     * 删除会员信息
     */
    @PreAuthorize("@ss.hasPermi('members:members:remove')")
    @Log(title = "会员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mhUserService.deleteMhUserByIds(ids));
    }
}
